from exts import db


class Order(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    title = db.Column(db.String(120))
    rihuali = db.Column(db.String(120))
    touziqixian = db.Column(db.String(120))
    qitoujine = db.Column(db.String(120))
    xiangmuguimo = db.Column(db.String(120))
    desc = db.Column(db.String(120))
    img = db.Column(db.String(120))

    def __init__(self,title,rihuali,touziqixian,qitoujine,xiangmuguimo,desc):
        self.title = title
        self.rihuali = rihuali
        self.touziqixian = touziqixian
        self.qitoujine = qitoujine
        self.xiangmuguimo = xiangmuguimo
        self.desc = desc
        
    def setImg(self,fileName):
        self.img = fileName
        db.session.commit();

    def __repr__(self):
        return '<Order %r>' % self.title

    def save(self):
        db.session.add(self)
        db.session.commit()

    def toDict(self):
        return {
            "id":self.id,
            "title":self.title,
            "rihuali":self.rihuali,
            "touziqixian":self.touziqixian,
            "qitoujine":self.qitoujine,
            "xiangmuguimo":self.xiangmuguimo,
            "desc":self.desc
        }

class Device(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    deviceid = db.Column(db.String(120))
    devicename = db.Column(db.String(120))
    projectname = db.Column(db.String(120))
    factoryname = db.Column(db.String(120))
    devicenumber = db.Column(db.String(120))

    def __init__(self,deviceid,devicename,projectname,factoryname,devicenumber):
        self.deviceid = deviceid
        self.devicename = devicename
        self.projectname = projectname
        self.factoryname = factoryname
        self.devicenumber = devicenumber

    def __repr__(self):
        return '<Device %r>' % self.devicename

    def save(self):
        db.session.add(self)
        db.session.commit()


class DeviceCheck(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    deviceid = db.Column(db.String(120))
    pub_date = db.Column(db.DateTime)
    projectname = db.Column(db.String(120))
    devicename = db.Column(db.String(120))
    uploadpeople = db.Column(db.String(120))
    role = db.Column(db.String(120))
    uploadlongitude = db.Column(db.String(120))
    uploadlatitude = db.Column(db.String(120))
    uploadimgname = db.Column(db.String(120))
    questioninfo = db.Column(db.String(120))

    def __init__(self,deviceid,projectname,devicename,uploadpeople,role,uploadlongitude,uploadlatitude,uploadimgname,questioninfo):
        self.deviceid = deviceid
        self.pub_date = datetime.utcnow()
        self.projectname = projectname
        self.devicename = devicename
        self.uploadpeople = uploadpeople
        self.role = role
        self.uploadlongitude = uploadlongitude
        self.uploadlatitude = uploadlatitude
        self.uploadimgname = uploadimgname
        self.questioninfo = questioninfo

    def __repr__(self):
        return '<Device %r>' % self.devicename

    def save(self):
        db.session.add(self)
        db.session.commit()